export default {
	state: {
		orderList: JSON.parse(localStorage.getItem("orderList")) || []
	},
	mutations: {
	  SET_ORDER_LIST(state, order) {
	    if (Array.isArray(order)) {
	      order.forEach(item => {
	        const index = state.orderList.findIndex(o => o.orderID === item.orderID);
	        if (index !== -1) {
	          state.orderList[index] = item; // 替换已有的订单
	        } else {
	          state.orderList.push(item); // 新增订单
	        }
	      });
	    } else {
	      const index = state.orderList.findIndex(o => o.orderID === order.orderID);
	      if (index !== -1) {
	        state.orderList[index] = order; // 替换已有的订单
	      } else {
	        state.orderList.push(order); // 新增订单
	      }
	    }
	    console.log("Updated order list:", state.orderList); // 打印更新后的 orderList
	    localStorage.setItem("orderList", JSON.stringify(state.orderList));
	  }
	},
	actions: {
		updateOrderList({
			commit
		}, order) {
			commit('SET_ORDER_LIST', order);
		}
	},
	getters: {
		orderList: (state) => state.orderList
	}
}